Sum of Three

Medium

Question

Write a function where given an list of integers, returns all unique triplets of integers that sum up to 0.

The order of the output and the order of the triplets should be sorted.

Input: [-1, 0, -2, 1, 3, 2]

Output: [[-2, -1, 3], [-2, 0, 2], [-1, 0, 1]]

Input: [-2, -1, 0, 0, 2, -1, 2, -2]

Output: [[-2, 0, 2], [-1, -1, 2]]

Clarify the problem

What are some questions you'd ask an interviewer?

Understand the problem

If the given list is [-5, 2, 1, -4, 3], which of these would be a single valid triplet?
[-5, -4, 1]
[3, -4, 1]
[-4, 2, 2]
[]

Login or signup to save your code.

Notes